const host=getApp().host;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    role:{},
    arr:[],
    name:'',
    host:''
  },

  handBut(e){
    // if(e.detail.value==""){
    //   return;
    // }
    this.setData({
      name:e.detail.value
    },()=>{
      this.toPage();
    })
  },

  formatDate(row) {
    let date = new Date(row.date);
    let month =
          date.getMonth() + 1 < 10
                ? "0" + (date.getMonth() + 1)
                : date.getMonth() + 1;
    let day =
          date.getDate() < 10
                ? "0" + date.getDate()
                : date.getDate();
    return (
          date.getFullYear() +
          "-" +
          month +
          "-" +
          day 
    );
  },  

  /**查看 */
  toPage(){
    wx.showLoading({
      title: '加载中',
    })
    let params='';
    params+='&name='+this.data.name;
    wx.request({
      url: host+'/client/contest/list?page=0&pageSize=100'+params,
      success:res=>{
        let list=res.data.data.list;
        list.forEach(item => {
          item.date=this.formatDate(item);
        });
        this.setData({
          arr:list
        },()=>{
          wx.hideLoading();
        })
      }
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let token=wx.getStorageSync('token')||null;
    if(token==null){
      wx.showModal({
        title: '提示',
        content: '请先登录',
        showCancel:false,
        success:res=> {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/login/login'
            })
          }
        }
      })
    }else{
      this.setData({
        role:wx.getStorageSync('role'),
        host:host
      },()=>{
        this.toPage();
      })
    }
  },

  formatTime(e){
    var time =  new Date(parseInt(e));
      var y = time.getFullYear();
      var m = time.getMonth()+1;
      var d = time.getDate();
      let t= y+'年'+m+'月'+d+'日';
    return t;
  },

})